import com.android.build.api.dsl.ApplicationExtension
import com.lean.android.plugin.convention.libs
import com.lean.plugin.AdConfigExtensions
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies

class AdConventionPlugin : Plugin<Project> {

    override fun apply(target: Project) {
        with(target) {
            with(pluginManager) {
                apply("com.leantech.android.plugin.flavor")
                apply("com.lean.plugin.ad-config")
            }

            configure<AdConfigExtensions> {
                baseUrl.set(libs.findVersion("adconfig-baseUrl").get().toString())
                fileName.set(libs.findVersion("adconfig-fileName").get().toString())
            }

            extensions.configure<ApplicationExtension> {
                dependencies {
                    add("implementation", libs.findLibrary("ad-sdk").get())
                    add("implementation", libs.findLibrary("vasdolly-provider").get())
                }
            }

        }
    }
}